
<template>
  <div class="dashboard">
    <div class="container">
      <!-- 左侧内容 -->
      <div class="left">
        <div class="panel">
          <!-- 个人信息 -->
          <div class="user-info">
            <img class="avatar" src="../../assets/common/company.png" />
            <div class="company-info">
              <div class="title">
                xx科技股份有限公司
                <!-- <span>体验版</span> -->
              </div>
              <div class="depart">{{ name }} | {{ departmentName }}</div>
            </div>
          </div>
          <!-- 代办 -->
          <div class="todo-list">
            <div class="todo-item">
              <span>组织总人数</span>
              <!-- 起始值 终点值  滚动时间 -->
              <count-to
                :start-val="0"
                :end-val="DataInfo.employeeTotal"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>正式员工</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.regularEmployeeTotal"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>合同待签署</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.contractSignTotal"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>待入职</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.toBeEmployed"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>本月待转正</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.toBeConfirmed"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>本月待离职</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.toBeDismissed"
                :duration="1000"
              />
            </div>
            <div class="todo-item">
              <span>接口总访问</span>
              <count-to
                :start-val="0"
                :end-val="DataInfo.interfaceAccessTotal"
                :duration="1500"
              />
            </div>
          </div>
        </div>
        <!-- 快捷入口 -->
        <div class="panel">
          <div class="panel-title">快捷入口</div>
          <div class="quick-entry">
            <div class="entry-item" @click="$router.push('/department')">
              <div class="entry-icon department" />
              <span>组织</span>
            </div>
            <div class="entry-item" @click="$router.push('/role')">
              <div class="entry-icon role" />
              <span>角色</span>
            </div>
            <div class="entry-item" @click="$router.push('/employee')">
              <div class="entry-icon employee" />
              <span>员工</span>
            </div>
            <div class="entry-item" @click="$router.push('/permission')">
              <div class="entry-icon permission" />
              <span>权限</span>
            </div>
            <div class="entry-item" @click="$router.push('/attendance')">
              <div class="entry-icon attendance" />
              <span>考勤</span>
            </div>
            <div class="entry-item" @click="$router.push('/approval')">
              <div class="entry-icon approval" />
              <span>审批</span>
            </div>
            <div class="entry-item" @click="$router.push('/salary')">
              <div class="entry-icon salary" />
              <span>工资</span>
            </div>
            <div class="entry-item" @click="$router.push('/social')">
              <div class="entry-icon social" />
              <span>社保</span>
            </div>
          </div>
        </div>
        <!-- 图表数据 -->
        <div class="panel">
          <div class="panel-title">社保申报数据</div>
          <div class="chart-container">
            <div class="chart-info">
              <div class="info-main">
                <span>申报人数</span>
                <count-to
                  :start-val="0"
                  :end-val="DataInfo.socialInsurance?.declarationTotal"
                  :duration="1000"
                />
              </div>
              <div class="info-list">
                <div class="info-list-item">
                  <span>待申报(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.socialInsurance?.toDeclareTotal"
                    :duration="1000"
                  />
                </div>
                <div class="info-list-item">
                  <span>申报中(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.socialInsurance?.declaringTotal"
                    :duration="1000"
                  />
                </div>
                <div class="info-list-item">
                  <span>已申报(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.socialInsurance?.declaredTotal"
                    :duration="1000"
                  />
                </div>
              </div>
            </div>
            <div class="chart">
              <!-- 社保图表 -->
              <div ref="social" style="width: 100%; height: 100%" />
            </div>
          </div>
        </div>

        <!-- 图表数据 -->
        <div class="panel">
          <div class="panel-title">公积金申报数据</div>
          <div class="chart-container">
            <div class="chart-info">
              <div class="info-main">
                <span>申报人数</span>
                <count-to
                  :start-val="0"
                  :end-val="DataInfo.providentFund?.declarationTotal"
                  :duration="1000"
                />
              </div>
              <div class="info-list">
                <div class="info-list-item">
                  <span>待申报(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.providentFund?.toDeclareTotal"
                    :duration="1000"
                  />
                </div>
                <div class="info-list-item">
                  <span>申报中(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.providentFund?.declaringTotal"
                    :duration="1000"
                  />
                </div>
                <div class="info-list-item">
                  <span>已申报(人)</span>
                  <count-to
                    :start-val="0"
                    :end-val="DataInfo.providentFund?.declaredTotal"
                    :duration="1000"
                  />
                </div>
              </div>
            </div>
            <div class="chart">
              <!-- 公积金图表 -->
              <div ref="provident" style="width: 100%; height: 100%" />
            </div>
          </div>
        </div>
      </div>
      <!-- 右侧内容 -->
      <div class="right">
        <!-- 帮助链接 -->
        <div class="panel">
          <div class="help">
            <div class="help-left">
              <div class="panel-title">帮助链接</div>
              <div class="help-list">
                <div class="help-block">
                  <i class="icon-entry" />
                  入门指南
                </div>
                <div class="help-block">
                  <i class="icon-help" />
                  在线帮助手册
                </div>
                <div class="help-block">
                  <i class="icon-support" />
                  联系技术支持
                </div>
                <div class="help-block">
                  <i class="icon-add" />
                  添加链接
                </div>
              </div>
            </div>
            <div class="help-right">
              <div class="calendar">
                <!-- <el-calendar /> -->
                <el-calendar />
              </div>
            </div>
          </div>
        </div>
        <!-- 通知公告 -->
        <div class="panel">
          <div class="panel-title">通知公告</div>
          <div class="information-list">
            <div class="information-list-item">
              <img src="@/assets/common/img.jpeg" alt="" />
              <div>
                <p>
                  <span class="col">管理员</span> 发布了
                  xx科技股份有限公司最佳员工获奖名单
                </p>
                <p>20020-05-21 14:25:08</p>
              </div>
            </div>
            <div class="information-list-item">
              <img src="@/assets/common/img.jpeg" alt="" />
              <div>
                <p>
                  <span class="col">管理员</span> 发布了
                  xx科技股份有限公司与xx国际外贸有限公司战略合作伙伴签约仪式
                </p>
                <p>2021-07-21 15:21:38</p>
              </div>
            </div>
            <div class="information-list-item">
              <img src="@/assets/common/img.jpeg" alt="" />
              <div>
                <p>
                  <span class="col">{{ name }}</span> 发布了
                  公司年度旅游活动安排
                </p>
                <p>{{ homeList[0]?.createTime }}</p>
              </div>
            </div>
          </div>
        </div>
        <div class="my-title">
          <el-tooltip content="点击我再来一句" placement="top" class="title">
            <el-button @click="getMusictitle()">每日情话小tips</el-button>
          </el-tooltip>
          <div class="tips">
            <el-button type="info" plain v-tippy="tips">点击我给你看</el-button>
            <el-button type="info" plain v-tippy="tips">点击我给你看</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import CountTo from "vue-count-to";
import { mapGetters } from "vuex";
import { getHomeData, getMessageList } from "@/api/home";
import axios from "axios";
// import * as echarts from "echarts"; // 引入所有的echarts
//echarts的按需引入
import * as echarts from "echarts/core"; // 引入核心包
import { LineChart, BarChart } from "echarts/charts"; // 引入折线图
import {
  GridComponent,
  TitleComponent,
  TooltipComponent,
} from "echarts/components"; // 引入组件
import { CanvasRenderer } from "echarts/renderers";
echarts.use([
  LineChart,
  GridComponent,
  CanvasRenderer,
  BarChart,
  TitleComponent,
  TooltipComponent,
]);

export default {
  components: {
    CountTo,
  },
  data() {
    return {
      DataInfo: {},
      homeList: [],
      tips: "",
    };
  },
  created() {
    this.getHomeData(), this.getMessageList();
    this.getMusictitle();
  },
  mounted() {
    // mounted的时候页面渲染完成了可以拿到对应的Dom元素
    // 初始化echart
    this.social = echarts.init(this.$refs.social);
    // data中没有声明 不是响应式
    this.provident = echarts.init(this.$refs.provident);
    tippy("#ajax-tippy", {
      content: "<div>${this.tips}</div>",
      flipOnUpdate: true,
    });
  },
  watch: {
    //因为数据的获取是异步的所以要监听当得到数据时将数据赋值给echarts
    DataInfo() {
      // console.log(this.homeData);
      // 设置图表
      this.social.setOption({
        title: {
          text: "每日社保申报人数",
        },
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: this.DataInfo.socialInsurance?.xAxis,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.DataInfo.socialInsurance?.yAxis,
            type: "line",
            areaStyle: {
              color: "#eea2a4", // 填充颜色
            },
            lineStyle: {
              color: "#ed5a65", // 线的颜色
            },
          },
        ],
      });
      //公积金
      this.provident.setOption({
        title: {
          text: "每日公积金申报人数",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: this.DataInfo.providentFund?.xAxis,
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "Direct",
            type: "bar",
            barWidth: "60%",
            data: this.DataInfo.providentFund?.yAxis,
          },
        ],
      });
    },
  },

  methods: {
    async getHomeData() {
      this.DataInfo = await getHomeData();
    },
    async getMessageList() {
      this.homeList = await getMessageList();
    },
    //tips数据
    getMusictitle() {
      axios
        .get("https://api.uomg.com/api/rand.qinghua?format=json")
        .then((res) => {
          this.tips = res.data.content;
          console.log(this.tips);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  computed: {
    ...mapGetters(["name", "departmentName"]),
  },
};
</script>

<style scoped lang="scss">
.dashboard {
  background: #f5f6f8;
  width: 100%;
  min-height: calc(100vh - 80px);

  ::v-deep .el-calendar-day {
    height: 40px;
  }
  ::v-deep .el-calendar-table__row td,
  ::v-deep .el-calendar-table tr td:first-child,
  ::v-deep .el-calendar-table__row td.prev {
    border: none;
  }
  .date-content {
    height: 40px;
    text-align: center;
    line-height: 40px;
    font-size: 14px;
  }
  .date-content .rest {
    color: #fff;
    border-radius: 50%;
    background: rgb(250, 124, 77);
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;
    font-size: 12px;
    margin-left: 10px;
  }
  .date-content .text {
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;
  }
  ::v-deep .el-calendar-table td.is-selected .text {
    background: #409eff;
    color: #fff;
    border-radius: 50%;
  }
  ::v-deep .el-calendar__header {
    display: none;
  }
  .container {
    display: flex;
    user-select: none;
    .right {
      width: 40%;
      .my-title {
        background: #fff;
        margin-left: 8px;
        margin-top: 10px;
        height: 410px;
        .title {
          display: block;
          width: 20%;
          margin: 0 auto;
          border-radius: 5px;
        }
        .tips {
          margin: 100px auto;
          text-align: center;
        }
      }
      .panel {
        margin-left: 8px;
      }
      :nth-child(1) {
        margin-top: 0;
      }
    }
    .left {
      flex: 1;
      :nth-child(1) {
        margin-top: 0;
      }
    }
    .panel {
      background-color: #fff;

      margin-top: 8px;
      padding: 20px;
      .panel-title {
        font-size: 16px;
        color: #383c4e;
        font-weight: 500;
      }
      // 用户信息样式
      .user-info {
        display: flex;
        .avatar {
          width: 24px;
          height: 24px;
          border-radius: 6px;
          line-height: 24px;
          text-align: center;
        }
        .username {
          width: 30px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          border-radius: 50%;
          background: #04c9be;
          color: #fff;
          margin-right: 4px;
        }
        .company-info {
          margin-left: 10px;
          height: 48px;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          .title {
            color: #383c4e;
            font-weight: 500;
            font-size: 16px;
            font-family: PingFang SC, PingFang SC-Medium;
            span {
              font-size: 12px;
              background: #f5f6f8;
              text-align: center;
              padding: 2px 8px;
              border-radius: 2px;
              color: #697086;
            }
          }
          .depart {
            font-size: 14px;
            color: #697086;
            font-weight: 400;
          }
        }
      }
      // 代办样式
      .todo-list {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        .todo-item {
          width: 18%;
          height: 90px;
          display: flex;
          flex-direction: column;
          padding: 10px;
          justify-content: space-around;
          :nth-child(1) {
            color: #697086;
            font-size: 14px;
          }
          :nth-child(2) {
            color: #383c4e;
            font-size: 30px;
            font-weight: 500;
          }
        }
      }
      // 快捷入口
      .quick-entry {
        margin-top: 16px;
        display: flex;
        justify-content: space-evenly;
        .entry-item:hover {
          cursor: pointer;
        }
        .entry-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          margin-left: 60px;
          &:nth-child(1) {
            margin-left: 0px;
          }
          .entry-icon {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            background: #f5f6f8;
            background-size: cover;
            &.approval {
              background-image: url("~@/assets/common/审批.png");
            }
            &.social {
              background-image: url("~@/assets/common/薪资明细.png");
            }
            &.salary {
              background-image: url("~@/assets/common/社保.png");
            }
            &.role {
              background-image: url("~@/assets/common/角色.png");
            }
            &.employee {
              background-image: url("~@/assets/common/员工概要.png");
            }
            &.permission {
              background-image: url("~@/assets/common/权限.png");
            }
            &.department {
              background-image: url("~@/assets/common/组织.png");
            }
            &.attendance {
              background-image: url("~@/assets/common/考勤.png");
            }
          }
          span {
            color: #697086;
            font-size: 14px;
            margin-top: 8px;
          }
        }
      }
      // 图表数据
      .chart-container {
        display: flex;
        .chart-info {
          width: 240px;
          margin-top: 10px;
          .info-main {
            padding: 10px;
            display: flex;
            flex-direction: column;
            :nth-child(1) {
              font-size: 14px;
            }
          }
          span {
            color: #697086;
            font-size: 14px;
            margin-top: 8px;
          }
        }
      }
      // 图表数据
      .chart-container {
        display: flex;
        .chart-info {
          width: 240px;
          margin-top: 10px;
          .info-main {
            padding: 10px;
            display: flex;
            flex-direction: column;
            :nth-child(1) {
              font-size: 14px;
              color: #697086;
            }
            :nth-child(2) {
              margin-top: 10px;
              font-size: 30px;
              color: #04c9be;
              font-weight: 500;
            }
          }
          .info-list {
            background: #f5f6f8;
            border-radius: 4px;
            padding: 12px 15px;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            .info-list-item {
              width: 50%;
              margin-top: 10px;
              display: flex;
              flex-direction: column;

              :nth-child(1) {
                font-size: 14px;
                color: #697086;
              }
              :nth-child(2) {
                margin-top: 10px;
                font-size: 30px;
                color: #383c4e;
                font-weight: 500;
              }
            }
          }
        }
        .chart {
          flex: 1;
        }
      }
      // 帮助链接
      .help {
        display: flex;
        .help-left {
          width: 40%;
          margin-right: 20px;
          .panel-title {
            text-align: center;
          }
        }
        .help-right {
          flex: 1;
          border-left: 10px solid #f5f6f8;
        }
        .help-list {
          .help-block {
            background: #f5f6f8;
            border-radius: 4px;
            width: 264px;
            height: 54px;
            padding: 17px 10px;
            font-size: 14px;
            color: #697086;
            margin-top: 10px;
            i {
              width: 14px;
              height: 14px;
              display: inline-block;
              background-size: cover;
              vertical-align: middle;
            }
            i.icon-help {
              background-image: url("~@/assets/common/help.png");
            }
            i.icon-support {
              background-image: url("~@/assets/common/support.png");
            }
            i.icon-add {
              background-image: url("~@/assets/common/add.png");
            }
            i.icon-entry {
              background-image: url("~@/assets/common/entry.png");
            }
          }
        }
      }
      // 通知公告
      .information-list {
        margin-top: 20px;
        .information-list-item {
          display: flex;
          align-items: center;
          margin: 15px 0;
          img {
            width: 40px;
            height: 40px;
            border: 50%;
          }
          .col {
            color: #8a97f8;
          }
          div :nth-child(2) {
            color: #697086;
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>